﻿
    using Maticsoft.BLL;
    using Maticsoft.Model;
    using System;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Utils;

    public partial class WebPage_SheZhi_Guangao : FBasePage
    {

        public DateTime end = new DateTime();
        
        public string height = "";
        public string hid = "";
        public string pageurl;
        public string pic;
        public DateTime start = new DateTime();
        public string strEndTime = DateTime.Now.AddDays(6.0).ToString("yyyy-MM-dd");
        public string strStartTime = DateTime.Now.ToString("yyyy-MM-dd");
        public string swf = "none";
        public string vis = "";
        public string width = "";

        public void AddLocation()
        {
            string str = base.Request["locationname"];
            int num = Convert.ToInt32(this.ddllocation.SelectedValue);
            int num2 = 0;
            DateTime now = DateTime.Now;
            int num3 = Convert.ToInt32(this.ddldisplay.SelectedValue);
            string text = this.txtheight.Text;
            Maticsoft.Model.Location model = new Maticsoft.Model.Location();
            Maticsoft.BLL.Location location2 = new Maticsoft.BLL.Location();
            model.locationname = str;
            model.pageurl = this.pageurl;
            model.location = new int?(num);
            model.type = new int?(num2);
            model.createdate = new DateTime?(now);
            model.visibility = num3;
            model.Begintime = DateTime.Parse(this.txtstart.Text);
            model.Endtime = DateTime.Parse(this.txtend.Text);
            model.width = this.txttitle.Text;
            model.height = text;
            if (location2.Add(model) > 0)
            {
                base.Response.Redirect("SheZhi_GongGaoList.aspx");
            }
            else
            {
                base.SetSuccess("设置失败");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.LocationButton();
        }

        public void Getlocation(int id)
        {
            Maticsoft.Model.Location model = new Maticsoft.Model.Location();
            model = new Maticsoft.BLL.Location().GetModel(id);
            this.locationname.Value = model.locationname;
            this.pageurl = model.pageurl;
            this.txttitle.Text = model.width;
            this.ddllocation.SelectedValue = model.location.ToString();
            this.ddldisplay.SelectedValue = model.visibility.ToString();
            this.txtheight.Text = model.height;
            DateTime begintime = model.Begintime;
            if ((model.Begintime.ToString() == "") || (model.Begintime.ToString() == "0001-1-1 0:00:00"))
            {
                this.strStartTime = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                this.strStartTime = model.Begintime.ToString("yyyy-MM-dd");
            }
            DateTime endtime = model.Endtime;
            if ((model.Endtime.ToString() == "") || (model.Endtime.ToString() == "0001-1-1 0:00:00"))
            {
                this.strEndTime = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                this.strEndTime = model.Endtime.ToString("yyyy-MM-dd");
            }
        }

        public void LocationButton()
        {
            string text = this.txtheight.Text;
            string url = "SheZhi_Guangao.aspx";
            if (base.Request["id"] != null)
            {
                url = url + "?id=" + base.Request["id"].ToString();
            }
            if (!Utility.IsNum(text))
            {
                this.SetError("请输入数字！");
                base.Response.Redirect(url);
            }
            else if (base.Request["id"] != null)
            {
                this.Update(Convert.ToInt32(base.Request["id"].ToString()));
            }
            else
            {
                this.AddLocation();
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "shezhi";
            this.SheZhi1.Select = "Go";
            if (!base.IsPostBack && (base.Request["id"] != null))
            {
                if (Utility.IsNum(base.Request["id"].ToString()))
                {
                    this.Getlocation(Convert.ToInt32(base.Request["id"].ToString()));
                }
                else
                {
                    this.SetError("您输入的参数非法");
                }
            }
        }

        public void Update(int id)
        {
            Maticsoft.Model.Location model = new Maticsoft.Model.Location();
            Maticsoft.BLL.Location location2 = new Maticsoft.BLL.Location();
            model = location2.GetModel(id);
            string str = base.Request["locationname"];
            int num = Convert.ToInt32(this.ddllocation.SelectedValue);
            int num2 = 0;
            DateTime now = DateTime.Now;
            int num3 = Convert.ToInt32(this.ddldisplay.SelectedValue);
            string text = this.txtheight.Text;
            model.id = id;
            model.locationname = str;
            model.pageurl = "";
            model.location = new int?(num);
            model.type = new int?(num2);
            model.createdate = new DateTime?(now);
            model.visibility = num3;
            model.width = this.txttitle.Text;
            model.height = text;
            model.Begintime = DateTime.Parse(base.Request.Form["txtstart"]);
            model.Endtime = DateTime.Parse(base.Request.Form["txtend"]);
            location2.Update(model);
            base.Response.Redirect("SheZhi_GongGaoList.aspx");
        }
    }



